<template>
  <div class="about">
    <van-search
      v-model="value"
      show-action
      label="地址"
      placeholder="请输入搜索关键词"
      @search="onSearch"
    >
      <template #action>
        <div @click="onSearch">搜索</div>
      </template>
    </van-search>

    <van-button @click="clear">清空</van-button>
    <ul>
      <li v-for="(item, index) in $store.state.history" :key="index">
        {{ item }}
      </li>
    </ul>
  </div>
</template>
<script>
import { Dialog } from "vant";

export default {
  data() {
    return {
      value: "",
    };
  },
  methods: {
    onSearch() {
      this.$store.commit("search", this.value);
      this.$router.push({ path: "/result", query: { value: this.value } });
    },
    clear() {
      Dialog.confirm({
        message: "是否删除历史记录",
      })
        .then(() => {
          // on confirm
          this.$store.commit("clear");
        })
        .catch(() => {
          // on cancel
        });
    },
  },
};
</script>
